<template>
  <div class="content-div">
    <van-row>
      <van-col span="24">
        <span style="color:#1989fa;;">*</span>
        <span class="warn-title">开启接单助手后，根据服务设置中设定好的价格自动匹配订单额度，可直接接单或自主报价。</span>
      </van-col>
    </van-row>
    <div class="mt8 card-div">
      <div class="title-div">订单模式</div>
      <van-cell-group>
        <van-cell title="报价模式">
          <template #right-icon>
            <van-switch v-model="checked" size="24px" />
          </template>
        </van-cell>
        <van-cell title="一口价订单">
          <template #right-icon>
            <van-switch v-model="checked1" size="24px" />
          </template>
        </van-cell>
      </van-cell-group>
    </div>
    <div class="gn-btn-box">
      <div class="gn-btn"  @click="saveSetting()">保存设置</div>
    </div>
  </div>
</template>
<script>
import { getTypeAccompanyingPhysician, updateTypeAccompanyingPhysician } from '@/api/medicalWaiter.js'
import { Toast } from 'vant'
export default {
  name: 'orderAssistant',
  data () {
    return {
      formItem: {},
      checked: null,
      checked1: null
    }
  },
  computed: {
    accompanying_physician_id () {
      return this.$store.state.user.severUserInfo.accompanying_physician_id
    }
  },
  methods: {
    saveSetting () {
      console.log('保存设置', this.formItem)
      if (this.checked === true && this.checked1 !== true) {
        this.formItem.type = '2'
      } else if (this.checked1 === true && this.checked !== true) {
        this.formItem.type = '1'
      } else if (this.checked1 === true && this.checked === true) {
        this.formItem.type = '3'
      } else if (this.checked1 !== true && this.checked !== true) {
        this.formItem.type = '0'
      }
      let param = {
        accompanying_physician_id: this.accompanying_physician_id,
        type: this.formItem.type
      }
      updateTypeAccompanyingPhysician(param).then(res => {
        if (res.data.errcode === 0) {
          Toast.success('设置成功')
          this.$router.push({
            name: 'mine-waiter'
          })
          return
        }
        Toast.fail(res.data.errmsg)
      })
    },
    getAccompanyingPhysicianInfo () {
      getTypeAccompanyingPhysician({ accompanying_physician_id: this.accompanying_physician_id }).then(res => {
        if (res.data.errcode === 0) {
          let type = res.data.data[0].type
          console.log(type)
          if (type === '0') {
            this.checked = false
            this.checked1 = false
          } else if (type === '1') {
            this.checked = false
            this.checked1 = true
          } else if (type === '2') {
            console.log('###')
            this.checked = true
            this.checked1 = false
            console.log(this.formItem)
          } else if (type === '3') {
            this.checked = true
            this.checked1 = true
          }
          // this.formItem = res.data.data
          return
        }
        Toast.fail(res.data.errmsg)
      })
    }
  },
  mounted () {
    this.getAccompanyingPhysicianInfo()
  }
}
</script>
<style scoped lang="less">
  .content-div {
    height: calc(100% - 17px) ;
    padding: 8px;
    font-family: PingFangSC;
    background-color: #f2f3f7;
    .warn-title {
      font-size: 11px;
      color: #232323;
      font-family: PingFangSC;
      word-break: break-all;
    }
    .card-div {
      padding: 10px 8px 0px 8px;
      background-color: #ffffff;
      .title-div {
        height: 17px;
        font-size: 12px;
        font-weight: 700;
        margin-left: 1px;
        margin-bottom: 13px;
        position: relative;
      }
      .title-div::before {
        position: absolute;
        content: '';
        width: 2px;
        height: 8px;
        left: -10px;
        top: 5px;
        background-color:#1989fa;
      }
      .van-cell {
        font-size: 12px;
      }
    }
    .gn-btn-box{
      height: 58px;
      position: fixed;
      // bottom: 50px; // 不显示底部tabbar暂时注释掉，需要的时候解开即可
      bottom: 0px;
      left: 0;
      background-color: #FFFFFF;
      width: 100%;
      box-sizing: border-box;
      padding: 10px;
      box-shadow: 0 0 10px 0 #CCCCCC;
      .gn-btn{
        height: 38px;
        line-height: 38px;
        text-align: center;
        background-color: rgba(89,89,255,.07);
        color: #1989fa;
        border-radius: 6px;
        box-sizing: border-box;
        border: 1px solid #1989fa;
      }
    }
    .mt8 {
      margin-top: 8px;
    }
    .flex {
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .row-center {
      justify-content: center;
    }
    .row-between {
      justify-content: space-between;
    }
  }
</style>
